class Solution
{
public:
    int smallestValue(int num)
    {
        int result = 0;
        int origin = num;
        for (int i = 2; i <= num; ++i)
        {
            while (num % i == 0)
            {
                num /= i;
                result += i;
            }
        }
        if (result == origin)
        {
            return result;
        }
        else
        {
            return smallestValue(result);
        }
    }
};